layui.use(['element','layer','jquery'], function(){
    var element = layui.element;
    if(layuiVersion > 1){
        element = layui.element;
    }else{
        element = layui.element();
    }
    var $ = layui.jquery;
    var layer = layui.layer;
    $(function(){
        $('#menuTree a').bind('click',function(){
            var url = $(this).attr("data-url");
            var id = $(this).attr("data-id");
            if(id){
                var title = $(this).text();
                if(!checkTabExist(id)){
                    var content =  '<p>Sorry, No URL...</p>';
                    if(url){
                        content =  '<iframe src=\''+url+'\' width=\'100%\' height=\'95%\' frameborder="0" scrolling="auto"></iframe>';
                    }
                    element.tabAdd('contentTab', {
                        title: title,
                        content: content,
                        id: id
                    })
                }
                element.tabChange('contentTab', id);
            }
        });
    })

    /*检查选项卡是否已经打开*/
    function checkTabExist(id){
        var bol = false;
        //debugger;
        $(".layui-tab-title").find("li").each(function(){
            //console.log($(this).attr('lay-id'));
            if($(this).attr('lay-id') == id){
                bol = true;
                return true;
            }
        })
        return bol;
    }

    /*隐藏左侧菜单*/
    $('.index-menu-toggle').on('click', function () {
        var sideWidth = $('#admin-side').width();
        if (sideWidth === 200) {
            $('#admin-body').animate({
                left: '0'
            }); //admin-footer
            $('#admin-footer').animate({
                left: '0'
            });
            $('#admin-side').animate({
                width: '0'
            });
        } else {
            $('#admin-body').animate({
                left: '200px'
            });
            $('#admin-footer').animate({
                left: '200px'
            });
            $('#admin-side').animate({
                width: '200px'
            });
        }
    });

    /*全屏*/
    $('.index-screen-full').on('click', function () {
        var docElm = document.documentElement;
        //W3C
        if (docElm.requestFullscreen) {
            docElm.requestFullscreen();
        }
        //FireFox
        else if (docElm.mozRequestFullScreen) {
            docElm.mozRequestFullScreen();
        }
        //Chrome等
        else if (docElm.webkitRequestFullScreen) {
            docElm.webkitRequestFullScreen();
        }
        //IE11
        else if (elem.msRequestFullscreen) {
            elem.msRequestFullscreen();
        }
        layer.msg('按Esc即可退出全屏');
    });

});